package com.university.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.university.infrastructure.Result;
import com.university.pojo.cqe.command.CmdFoodOrder;
import com.university.pojo.cqe.query.FoodQuery;
import com.university.pojo.dto.FoodOrderDTO;
import com.university.service.FoodOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Date: 2021/5/15 17:56
 * @Description:
 */
@Api(tags = {"食品饮料订单接口"})
@RestController
public class FoodOrderController extends BaseController {

    @Resource
    private FoodOrderService foodOrderService;

    @ApiOperation("用户购买食品饮料")
    @PostMapping("/user/saveFoodOrder")
    public Result saveFoodOrder(@RequestBody List<CmdFoodOrder> list) {
        foodOrderService.saveFoodOrder(list);
        return ok();
    }

    @ApiImplicitParam(name = "username", value = "用户名", required = true, dataTypeClass = String.class)
    @ApiOperation("用户查询小食订单")
    @GetMapping("/user/getFoodOrder")
    public Result getFoodOrder(String username) {
        FoodQuery query = new FoodQuery();
        query.setUsername(username);
        List<FoodOrderDTO> orderList = foodOrderService.userGetFoodOrder(query);
        return ok(orderList);
    }

    @ApiOperation("管理员查询订单")
    @GetMapping("/admin/getFoodOrder")
    public Result getFoodOrder(String username,
                               @RequestParam(defaultValue = "1") Long page,
                               @RequestParam(defaultValue = "10") Long pageSize) {
        FoodQuery query = new FoodQuery();
        query.setUsername(username);
        query.setPage(page);
        query.setPageSize(pageSize);
        IPage<FoodOrderDTO> orderList = foodOrderService.adminGetFoodOrder(query);
        return ok(orderList);
    }

}
